VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsRecordset"
Attribute VB_GlobalNameSpace = True
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'xwelx 04.2010

Option Explicit

'Opens a recordset
Public Sub OpenRecordset(rsName As ADODB.Recordset, ColumnName As String, TableName As String, _
            Optional Condition As String, Optional WithoutCOID As Boolean)
Dim oString As New clsDeclaration
Dim oDB As New clsConnection

    With rsName
        If Trim(Condition) <> "" Then
            If Not WithoutCOID Then
                Condition = Condition & " AND cCompanyID = '" & Trim(oString.COID) & "'"
            End If
        Else
            If Not WithoutCOID Then
                Condition = "WHERE cCompanyID = '" & Trim(oString.COID) & "'"
            End If
        End If
        
        oString.sSQL = "SELECT " & ColumnName & " FROM " & TableName & " " & Condition
        
        If .State <> adStateOpen Then
            .CursorLocation = adUseClient
            .Open oString.sSQL, oDB.cn, adOpenStatic, adLockBatchOptimistic
            .MarshalOptions = adMarshalModifiedOnly
            .CacheSize = 50
        End If
    End With
    
    Set oString = Nothing
    Set oDB = Nothing

End Sub

'Opens a recordset with new refreshed/connection
Public Sub OpenRecordsetWithCN(rsName As ADODB.Recordset, ColumnName As String, TableName As String, _
            cConn As ADODB.Connection, Optional Condition As String, Optional WithoutCOID As Boolean)
On Error Resume Next

Dim oString As New clsDeclaration

    With rsName
        If Trim(Condition) <> "" Then
            If Not WithoutCOID Then
                Condition = Condition & " AND cCompanyID = '" & Trim(oString.COID) & "'"
            End If
        Else
            If Not WithoutCOID Then
                Condition = "WHERE cCompanyID = '" & Trim(oString.COID) & "'"
            End If
        End If
        
        oString.sSQL = "SELECT " & ColumnName & " FROM " & TableName & " " & Condition
        
        If .State <> adStateOpen Then
            .CursorLocation = adUseClient
            .Open oString.sSQL, cConn, adOpenStatic, adLockBatchOptimistic
            .MarshalOptions = adMarshalModifiedOnly
            .CacheSize = 50
        End If
    End With
    
    Set oString = Nothing
End Sub

'For computation of actual product balance
Public Sub ProductBalanceCommand(rsName As ADODB.Recordset, ProductID As String)
Dim cmd As New ADODB.Command
Dim oString As New clsDeclaration
Dim oDB As New clsConnection
    
    With cmd
        .ActiveConnection = oDB.cn
        .CommandTimeout = 1000
        .CommandText = "SP_ProductBalanceInquiry_Module"
        .CommandType = adCmdStoredProc
        .Parameters("@cItemNo") = ProductID
        .Parameters("@cCompanyID") = oString.COID
    End With
    
    Set rsName = cmd.Execute()
    
    Set oString = Nothing
    Set oDB = Nothing
    
End Sub

'For computation of credit limit per client
Public Sub CreditLimitCommand(rsName As ADODB.Recordset, CustomerID As String, MSCode As String)
Dim cmd As New ADODB.Command
Dim oString As New clsDeclaration
Dim oDB As New clsConnection

    With cmd
        .ActiveConnection = oDB.cn
        .CommandTimeout = 1000
        .CommandText = "SP_CG"
        .CommandType = adCmdStoredProc
        .Parameters("@cCode") = CustomerID
        .Parameters("@cMSCode") = MSCode
        .Parameters("@cCompanyID") = oString.COID
    End With
    
    Set rsName = cmd.Execute()
    
    Set oString = Nothing
    Set oDB = Nothing
    
End Sub

'For computation of credit limit per parent customer (group code)
Public Sub CreditLimitPCCommand(rsName As ADODB.Recordset, GroupCode As String, ClassCode As String)
Dim cmd As New ADODB.Command
Dim oString As New clsDeclaration
Dim oDB As New clsConnection

    With cmd
        .ActiveConnection = oDB.cn
        .CommandTimeout = 1000
        .CommandText = "SP_CG_PC"
        .CommandType = adCmdStoredProc
        .Parameters("@cGroupCode") = GroupCode
        .Parameters("@cClassCode") = ClassCode
        .Parameters("@cCompanyID") = oString.COID
    End With
    
    Set rsName = cmd.Execute()
    
    Set oString = Nothing
    Set oDB = Nothing
    
End Sub

Public Sub ProductAgeing(rsName As ADODB.Recordset, ProductID As String, Interval As Integer)
Dim cmd As New ADODB.Command
Dim oString As New clsDeclaration
Dim oDB As New clsConnection

    With cmd
        .ActiveConnection = oDB.cn
        .CommandTimeout = 1000
        .CommandText = "rsp_Inventory_Product_Aging"
        .CommandType = adCmdStoredProc
        .Parameters("@cCompName") = ""
        .Parameters("@cAddress1") = ""
        .Parameters("@cAddress2") = ""
        .Parameters("@cReportTitle") = ""
        .Parameters("@cCriteria1") = ""
        .Parameters("@cCriteria") = ""
        .Parameters("@cFrom") = ProductID
        .Parameters("@cTo") = ProductID
        .Parameters("@dDateFROM") = Now - Interval
        .Parameters("@dDateTo") = Now
        .Parameters("@cCompID") = oString.COID
        .Parameters("@nInterval") = Interval
        .Parameters("@cValue1") = ""
        .Parameters("@cValue2") = ""
        .Parameters("@cValue3") = ""
        .Parameters("@cValue4") = ""
        .Parameters("@cValue5") = ""
        .Parameters("@cValue6") = ""
    End With
    Set rsName = cmd.Execute()
    
    Set oString = Nothing
    Set oDB = Nothing
End Sub

Public Function ExistingWithinRecordset(rsName As ADODB.Recordset, Condition As String) As Boolean
On Error Resume Next
Dim clone_rs As ADODB.Recordset
Set clone_rs = rsName.Clone
      
    ExistingWithinRecordset = False
    
    
    clone_rs.Filter = Condition

    If clone_rs.EOF Or clone_rs.BOF Then
        If rsName.RecordCount <> 0 Then rsName.MoveLast
        ExistingWithinRecordset = False
    Else
        rsName.Bookmark = clone_rs.Bookmark
        ExistingWithinRecordset = True
    End If

    clone_rs.Close
    Set clone_rs = Nothing
      
End Function

